<!DOCTYPE html>
<html>

<head>
    <title>游记列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script>
        $(function () {


            //当前页
            var currentPage=1;
            //总页数
            var pages;
            //是否查询的标记
            var loading=false;
            //用户存储游记的数组容器
            var travelData=[];
            //查询方fa
            function query() {
                //如果正在查询就不继续查了,退出
                if (loading) {
                    return;
                }
                //设置为查询状态
                loading=true;
                $.get("/travels",{currentPage:currentPage},function (data) {
                    console.log(data);
                    //把查询的数据放到容器中
                    $.merge(travelData,data.list);
                    //将容器封装到属性为list的对象中
                    var json = {list:travelData};
                    //渲染数据
                    $("#allTravels").renderValues(json,{
                        getHref:function(item,value) {
                            var url = $(item).data("url");
                            $(item).attr('href', url + value);
                        }
                    });
                    //当前页+1
                    currentPage++;
                    //总页数
                    pages=data.pages;
                    //设置为没有在查询  本次查询结束
                    loading=false;
                });
            }


            //默认查询第一页
            query();

            //滚动页面 触发事件 翻页
            $(window).scroll(function () {
                //判断是否滚动到底部了  窗口的高度+文档滚动的高度 大于等于 文档的高度
                if($(window).height()+$(document).scrollTop()+1>=$(document).height()){
                    //如果当前页大于总页数就不查询了
                    if(currentPage<=pages){
                        //查询
                        query();
                    }else{
                        $(document).dialog({
                            type : 'notice',
                            infoText: '亲,已经到底了',
                            autoClose: 1500,
                            position: 'center'  // center: 居中; bottom: 底部
                        });
                    }

                }
            });

            //发送请求去查询  获取最近三月的游记推荐数据
            $.get("/travels/commends",{type:2,pageSize:3},function (data) {
                console.log(data);
                //渲染数据
                $("#travelsCommends").renderValues(data,{
                    getHref:function(item,value) {
                        var url = $(item).data("url");
                        $(item).attr('href', url + value);
                    }
                });
                //默认选择第一页
                $(".carousel-item:first").addClass("active");
            });

            //当点击搜索框的时候清空搜索框
            $("#search").val("");
            //给搜索绑定点击事件
            $("#searchBtn").click(function () {
                //console.log($("#search").val());
                //获取搜索框中的数据
                var keyword=$("#search").val();
                //判断是否有值,有值再进行跳页面搜索
                if(keyword==null||keyword.length==0){
                    //使用提示框进行提示
                    $(document).dialog({
                        titleText:"温馨提示",
                        content:"搜索内容不能为空"
                    });
                }else{
                    //有值就进行跳转页面并将关键字数据带上
                    window.location.href="/strategySearch.html?keyword="+keyword+"&&type="+2
                }
            });
        });
    </script>


</head>

<body>


<div class="search-head">
    <div class="row nav-search">
        <div class="col-1">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-8">
            <div class="input-group-sm search">
                <input id="search" class="form-control" placeholder="搜索旅行攻略、日记和旅游资讯">
            </div>
        </div>
        <!--搜索放大镜按钮-->
        <div class="col-1">
            <i class="fa fa-search" id="searchBtn"
               style="color:white;font-size:25px;position: absolute;top: 23%;left: 88%">
            </i>
        </div>
    </div>
</div>


<div class="container">

    <h6>每月冠军游记</h6>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div id="travelsCommends" class="carousel-inner">
            <div render-loop="list"><div class="carousel-item ">
                <div class="border commend">
                    <a render-fun="getHref" render-key="list.travelId" data-url="/travelContent.html?id=" >
                        <img render-src="list.coverUrl" width="100%" height="200px">
                        <h1 render-html="list.title"> 骨灰级成都吃货地图</h1>
                        <small render-html="list.subTitle">成都成都</small>
                    </a>
                </div>
            </div></div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
    </div>
</div>

<div class="container">
    <h6>全部游记</h6>
    <div id="allTravels">
        <div render-loop="list">
            <div class="row detail">
                <div class="col">
                    <!--render-key是指值从哪里来,render-fun是指渲染的时候要调用的方法名字-->
                    <a render-fun="getHref" render-key="list.id" data-url="/travelContent.html?id=" >
                        <h4 render-html="list.title"></h4>
                    </a>
                    <p>
                        <!--render-key是指值从哪里来,render-fun是指渲染的时候要调用的方法名字-->
                        <a render-fun="getHref" render-key="list.author.id" data-url="/userProfiles.html?id=" >
                            <img class="rounded-circle head-img" render-src="list.author.headImgUrl">
                            <span render-html="list.author.nickName"></span>
                        </a> 在
                        <span class="addr" render-html="list.place.name" ></span>
                    </p>
                    <p>
                        <i class="fa fa-eye fa-fw"></i>
                        <span render-html="list.watchNum"></span>
                        <i class="fa fa-commenting fa-fw"></i>
                        <span render-html="list.visitNum"></span>
                    </p>
                </div>
                <div class="col bigimg">
                    <a render-fun="getHref" render-key="list.id" data-url="/travelContent.html?id=" >
                        <img render-src="list.coverUrl">
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>



</body>

</html>